<?php
namespace Util\Form;

class Form {

	protected $_classes;
	
	protected $_attributes;
	
	protected $_elements;
	
	public function __construct(){
		$this->_classes		= array();
		$this->_attributes	= array(
			"method" => "post",
			"action" => "",
		);
		$this->_elements	= array();
	}
	
	public function addElement($element){
		$this->_elements[] = $element;
	}
	
	public function addElements($elements){
		$this->_elements = array_merge($this->_elements, $elements);
	}
	
	public function setAttribute($name, $value){
		$this->_attributes[$name] = $value;
	}
	
	public function setAttributes($attributes){
		$this->_attributes = array_merge($this->_attributes, $attributes);
	}
	
	public function addClass($class){
		$this->_classes[$class] = $class;
	}
	
	public function getElements() {
		return $this->_elements;
	}
	
	public function getAttributes(){
		return $this->_attributes;
	}
	
	public function getClasses(){
		return $this->_classes;
	}
	
	public function validate(){
		$errors = array();
		$elements = $this->getElements();
		foreach ($elements as $key => $element) {
			$elementErrors = $element->validate();
			if (!empty($elementErrors)){
				$errors[$key] = $elementErrors;
			}
		}
		return $errors;
	}
	
}

?>